<template>
    <div class="newsinfo-container">
        <h3 class="title">{{listinfo.title}}</h3>
        <p class="subtitle">
            <span>发表时间：{{listinfo.add_time | dataFormat}}</span>
            <span>点击：{{listinfo.click}}次</span>
        </p>
        <hr>
        <div class="content" v-html="listinfo.content"></div>   

        <comment :id="this.id"></comment>   
    </div>
</template>

<script>

// 导入评论子组件
import comment from "../subcomponents/comment.vue";

export default {
    data() {
        return {
            id: this.$route.params.id,
            listinfo: {},
        }
    },
    created() {
        this.getnewsinfo();
    },
    methods: {
        getnewsinfo() {
            this.$http.get("api/getnew/" + this.id).then(result => {
                console.log(result);
                if(result.body.status === 0) {
                    this.listinfo = result.body.message[0];
                } else {
                    alert("获取数据失败");
                }
            })
        }
    },
    components: {
        'comment': comment
    }
}
</script>

<style lang="scss">
.newsinfo-container {
    padding: 0 4px;
    .title {
        font-size: 16px;
        text-align: center;
        margin: 15px 0;
        color: red;
    }
    .subtitle {
        font-size: 13px;
        color: blue;
        display: flex;
        justify-content: space-between;
    }
}
</style>
